/*
 * @Description: 
 * @Author: zoe
 * @Date: 2024-09-26 09:14:09
 * @LastEditors: rendc
 * @LastEditTime: 2024-09-29 14:47:08
 */
import java.util.Collection;
import java.util.ArrayList;
@SuppressWarnings("unchecked")
public class Test01Collection{
    public static void main(String[] args) {
        //创建一个集合对象
        //接口 变量名 = new 实现类();
        //在声明集合时，指定泛型参数可以提高代码的可读性和类型安全性
        //Collection<String> c = new ArrayList<String>();
        //上述类型只能放Stirng类型的值
        Collection c = new ArrayList();
        //判断集合是否为空
        if (c.isEmpty()) {
            System.out.println("集合为空");
        } else {
            System.out.println("集合不为空");
        }
        c.add("hello,world");
        c.add(1);
        c.add('a');
        System.out.println("c:" + c);
        String str = new String("removeMe");
        c.add(str);
        System.out.println("c:" + c);
        System.out.println(c.size());
        System.out.println(c.remove(str));
        System.out.println(c.size());
        System.out.println("c" + c);
        //将单列结合转换为数组
        Object[] objArr = c.toArray();
        //遍历数组元素
        for(Object obj : objArr){
            System.out.println(obj);
        }       
       
    }
}